﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBQLTV;

namespace DAO
{
    public class ThongKeSachTraTreDAO
    {
        public THONGKESACHTRATRE InsertThongKeSachTraTre(string Ngay)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                string ShortDateString = Convert.ToDateTime(Ngay).ToShortDateString();
                DateTime ngay = Convert.ToDateTime(ShortDateString);
                THONGKESACHTRATRE tk = entity.THONGKESACHTRATREs.FirstOrDefault(o => o.NgayLapThongKe.Equals(ngay));
                
                if (tk != null)
                    return tk;
                else
                {
                    THONGKESACHTRATRE thongKe = new THONGKESACHTRATRE()
                    {
                        NgayLapThongKe = ngay
                    };
                    entity.THONGKESACHTRATREs.AddObject(thongKe);
                    entity.SaveChanges();
                    return thongKe;
                }
            }
        }
        public THONGKESACHTRATRE GetThongKeTraTre(string Ngay)
        {
            using (DBQUANLYTHUVIENEntities entity = new DBQUANLYTHUVIENEntities())
            {
                string ShortDateString = Convert.ToDateTime(Ngay).ToShortDateString();
                DateTime ngay = Convert.ToDateTime(ShortDateString);
                THONGKESACHTRATRE tk = entity.THONGKESACHTRATREs.FirstOrDefault(o => o.NgayLapThongKe.Equals(ngay));
                return tk;
            }
        }
    }
}
